﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Common.LoggingManager;
using Business.Operations;

namespace HPDMAS
{
    public partial class _Default : System.Web.UI.Page
    {
        private int _sehirId;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ddlSehir.DataSource = SehirOperation.SehirAdiGetAll();
                ddlSehir.DataBind();
                ddlSehir.SelectedValue = "UŞAK";
            }

            _sehirId = SehirOperation.SehirIdGetBySehirAdi(ddlSehir.SelectedValue);
            GridView1.DataSource = MusabakaOperation.MusabakaAnonimGetAllGetBySehirId(_sehirId);
            GridView1.DataBind();
        }

        protected void ddlSehir_SelectedIndexChanged(object sender, EventArgs e)
        {
            _sehirId = SehirOperation.SehirIdGetBySehirAdi(ddlSehir.SelectedValue);
            GridView1.DataSource = MusabakaOperation.MusabakaAnonimGetAllGetBySehirId(_sehirId);
            GridView1.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = DateTime.Parse(e.Row.Cells[0].Text).ToString("dd/MM/yyyy");
                e.Row.Cells[1].Text = DateTime.Parse(e.Row.Cells[1].Text).ToString("dddd");
                e.Row.Cells[2].Text = DateTime.Parse(e.Row.Cells[2].Text).ToString("hh:mm");
            }
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            GridView1.DataBind();
        }
    }
}
